<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="../style/main.css" type="text/css" rel="stylesheet">
        <link href="../style/manager.css" type="text/css" rel="stylesheet">
        <script type="text/javascript" src="../script/jquery-1.8.2.js"></script>
        <script type="text/javascript" src="../script/SMScript.js"></script>
        <title></title>
    </head>
    <body>
        <header>
        <?php
        require_once('..\libchart\classes\libchart.php');
        session_start();
        mysql_connect("localhost:3306", "root", "16886611");
        mysql_select_db("digitalsales");
        
        if(isset($_GET["action"])){
            if($_GET["action"]=="logout"){
               $_SESSION["manager"]=NULL;
               header("location:index.php");
            }
        }
        if(!isset($_SESSION["manager"])||$_SESSION["manager"]==NULL){
            echo '<ul>
                 <li>
                    <p>YOU HAVE NOT LOGGED IN YET</p>
                  </li>
                </ul>';
        }else{
            echo '<ul>
                <li id="logout">
                  <p><a href="index.php?action=logout">Log out</a></p>
                </li>
                  <li>
                    <p>Welcome back,'.$_SESSION["manager"].'!</p>
                  </li>
                </ul>';
        }
        
        ?>
        </header>
        <div class="transparentMainpanel">
            <div class="options">
                <?php echo '<h2>At your service, '.$_SESSION["manager"].'</h2>'; ?>
                <div class="optionlist">
                    <table>
                        <tbody>
                            <?php 
                            $selection="option1";
                            if(isset($_GET["option"])){
                               $selection=$_GET["option"];
                            }
                            $addtion1="style='visibility: hidden'";
                            $addtion2="style='visibility: hidden'";
                            $addtion3="style='visibility: hidden'";
                            $textStyle1="style='text-decoration-line:  none'";
                            $textStyle2="style='text-decoration-line:  none'";
                            $textStyle3="style='text-decoration-line:  none'";
                            switch ($selection){
                                case "option1":
                                    $addtion1="style='visibility: visible'";
                                    $textStyle1="style='text-decoration-line:underline'";
                                    break;
                                case "option2":
                                    $addtion2="style='visibility: visible'";
                                    $textStyle2="style='text-decoration-line:underline'";
                                    break;
                                case "option3":
                                    $addtion3="style='visibility: visible'";
                                    $textStyle3="style='text-decoration-line:underline'";
                                    break;
                            }
                            echo   '<tr id="option1"><td><img src="../images/star.gif"  class="optionimg" '.$addtion1.'></td><td '.$textStyle1.'><p class="optiontext" >General Status Report</p></td></tr>
                                    <tr id="option2"><td><img src="../images/star.gif"  class="optionimg" '.$addtion2.'></td><td '.$textStyle2.'><p class="optiontext" >Region-Performance Report</p></td></tr>
                                    <tr id="option3"><td><img src="../images/star.gif"  class="optionimg" '.$addtion3.'></td><td '.$textStyle3.'><p class="optiontext" >Products Evaluation</p></td></tr>';
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="reportPanel">
                <?php 
                $style1="";
                $style2="style='background-color:activecaption;margin-left:5px'";
                $style3="style='background-color:activecaption;margin-left:5px'";
                $subcondition="Monthly";
                if(isset($_GET["subcondition"])){
                    switch ($_GET["subcondition"]){
                        case "daily":
                            $subcondition="Daily";
                            $style1="style='background-color:activecaption;'";
                            $style2="style='margin-left:5px'";
                            $style3="style='background-color:activecaption;margin-left:5px'";
                            break;
                        case "monthly":
                            $style1="";
                            $style2="style='background-color:activecaption;margin-left:5px'";
                            $style3="style='background-color:activecaption;margin-left:5px'";
                            break;
                        case "yearly":
                            $subcondition="Yearly";
                            $style1="style='background-color:activecaption;'";
                            $style2="style='background-color:activecaption;margin-left:5px'";
                            $style3="style='margin-left:5px'";
                            break;
                    }
                }
                ?>
               
                        <div class="tagList">
                            <div id="tag1" class="tag" <?php echo $style1;?>>
                                <h2>Monthly<br/>Report</h2>
                            </div>
                            <div id="tag2" class="tag" <?php echo $style2;?>>
                                <h2>Daily<br/>Report</h2>
                            </div>
                            <div id="tag3" class="tag" <?php echo $style3;?>>
                                <h2>Yearly<br/>Report</h2>
                            </div>
                            <div style="clear:both;"></div>
                        </div>
                        
                        <div class="report">
                            <?php 
                            $type="";
                            switch ($selection){
                                case "option1":
                                    $type="General Status";
                                    break;
                                case "option2":
                                    $type="Region Performance";
                                    break;
                                case "option3":
                                    $type="Products Analyze";
                                    break;
                            }
                            $title=$subcondition." ".$type." Report for DigitalSales Inc.";
                            echo '<h2>'.$title.'</h2>';
                            switch ($subcondition." ".$type){
                                case "Monthly General Status":
                                    $statsql1 = "select MONTH(tr.date), SUM(tr.quantity*(tr.price - ps.cost))/1000 as totalProfit
                                        from product_stores ps , transactions tr where tr.product = ps.PID AND tr.store = ps.SID
                                        AND EXTRACT(MONTH FROM '2012-10-30')-EXTRACT(MONTH FROM tr.date)<=10 group by MONTH(tr.date)";
                                    $result1=mysql_query($statsql1);
                                    $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res1=mysql_fetch_row($result1)){
                                         $dataSet->addPoint(new Point($res1[0],intval($res1[1])));
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Profit Report for Recent Months(Thousand Dollars)");
                                    $chart->render("../images/HaoChart/Top_Month_General.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Month_General.png">';
                                    $statsql2 = "select s.region,sum((tr1.price-ps1.cost)*tr1.quantity) from stores s, transactions tr1,product_stores ps1 where tr1.product=ps1.pid and tr1.store=ps1.sid and ps1.sid=s.storeid 
                                        AND EXTRACT(MONTH FROM '2012-10-30')-EXTRACT(MONTH FROM tr1.date)<=1 group by s.region";
                                    $result2=mysql_query($statsql2);
                                    $chart2 = new PieChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet2 = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res2=mysql_fetch_row($result2)){
                                         $dataSet2->addPoint(new Point($res2[0],intval($res2[1])));
                                    }
                                    $chart2->setDataSet($dataSet2);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart2->setTitle("Profit Proportion of Regions In the recent Months");
                                    $chart2->render("../images/HaoChart/Top_Month_General_Ranks.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Month_General_Ranks.png">';
                                    break;
                                case "Daily General Status":
                                    $statsql1 = "select DAY(tr.date), SUM(tr.quantity*(tr.price - ps.cost))/1000 as totalProfit
                                        from product_stores ps , transactions tr where tr.product = ps.PID AND tr.store = ps.SID
                                        AND EXTRACT(DAY FROM '2012-10-30')-EXTRACT(DAY FROM tr.date)<=10 group by DAY(tr.date)";
                                    $result1=mysql_query($statsql1);
                                    $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res1=mysql_fetch_row($result1)){
                                         $dataSet->addPoint(new Point($res1[0],  intval($res1[1])));
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Profit Report for Recent Days(Thousand Dollars)");
                                    $chart->render("../images/HaoChart/Top_Day_General.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Day_General.png">';
                                    $statsql2 = "select s.region,sum((tr1.price-ps1.cost)*tr1.quantity) from stores s, transactions tr1,product_stores ps1 where tr1.product=ps1.pid and tr1.store=ps1.sid and ps1.sid=s.storeid 
                                        AND EXTRACT(DAY FROM '2012-10-30')-EXTRACT(DAY FROM tr1.date)<=1 group by s.region";
                                    $result2=mysql_query($statsql2);
                                    $chart2 = new PieChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet2 = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res2=mysql_fetch_row($result2)){
                                         $dataSet2->addPoint(new Point($res2[0],  intval($res2[1])));
                                    }
                                    $chart2->setDataSet($dataSet2);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart2->setTitle("Profit Proportion of Regions In the recent Days");
                                    $chart2->render("../images/HaoChart/Top_Day_General_Ranks.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Day_General_Ranks.png">';
                                    break;
                                case "Yearly General Status":
                                    $statsql1 = "select YEAR(tr.date), SUM(tr.quantity*(tr.price - ps.cost))/1000 as totalProfit
                                        from product_stores ps , transactions tr where tr.product = ps.PID AND tr.store = ps.SID
                                        AND EXTRACT(YEAR FROM '2012-10-30')-EXTRACT(YEAR FROM tr.date)<=10 group by YEAR(tr.date)";
                                    $result1=mysql_query($statsql1);
                                    $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res1=mysql_fetch_row($result1)){
                                         $dataSet->addPoint(new Point($res1[0],  intval($res1[1])));
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Profit Report for Recent Years(Thousand Dollars)");
                                    $chart->render("../images/HaoChart/Top_Year_General.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Year_General.png">';
                                    $statsql2 = "select s.region,sum((tr1.price-ps1.cost)*tr1.quantity) from stores s, transactions tr1,product_stores ps1 where tr1.product=ps1.pid and tr1.store=ps1.sid and ps1.sid=s.storeid 
                                        AND EXTRACT(YEAR FROM '2012-10-30')-EXTRACT(YEAR FROM tr1.date)<=1 group by s.region";
                                    $result2=mysql_query($statsql2);
                                    $chart2 = new PieChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet2 = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res2=mysql_fetch_row($result2)){
                                         $dataSet2->addPoint(new Point($res2[0],  intval($res2[1])));
                                    }
                                    $chart2->setDataSet($dataSet2);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart2->setTitle("Profit Proportion of Regions In the recent Years");
                                    $chart2->render("../images/HaoChart/Top_Year_General_Ranks.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Year_General_Ranks.png">';
                                    break;
                                case "Monthly Region Performance":
                                    $statsql1 = "select s.region,MONTH(tr1.date),sum((tr1.price-ps1.cost)*tr1.quantity)/1000 from stores s, transactions tr1,product_stores ps1 where tr1.product=ps1.pid and tr1.store=ps1.sid and ps1.sid=s.storeid 
                                        AND EXTRACT(MONTH FROM '2012-10-30')-EXTRACT(MONTH FROM tr1.date)<=10 group by s.region,MONTH(tr1.date)";
                                    $result1=mysql_query($statsql1);
                                    $regioname="";
                                    $drawingstate="unstarted";
                                    $chart;
                                    $dataSet;
                                    while ($res1=mysql_fetch_row($result1)){
                                        if($res1[0]!=$regioname){
                                            if($drawingstate=="unstarted"){
                                                $regioname=$res1[0];
                                                $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                                $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                                $drawingstate="started";
                                            }else{
                                                $drawingstate="finished";
                                            }
                                        }
                                        if($drawingstate=="finished"){
                                            $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                            $chart->setTitle("Profit Report for Recent Months for ".$regioname."(Thousand Dollars)");
                                            $chart->render("../images/HaoChart/Top_Month_Region_".$regioname.".png");//这里需要一个路径和文件名称
                                            echo '<img src="../images/HaoChart/Top_Month_Region_'.$regioname.'.png">';
                                            $regioname=$res1[0];
                                            $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                            $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                            $drawingstate="started";
                                        }
                                        $dataSet->addPoint(new Point($res1[1],intval($res1[2])));
                                        
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Profit Report for Recent Months for ".$regioname."(Thousand Dollars)");
                                    $chart->render("../images/HaoChart/Top_Month_Region_".$regioname.".png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Month_Region_'.$regioname.'.png">';
                                    break;
                                case "Daily Region Performance":
                                    $statsql1 = "select s.region,DAY(tr1.date),sum((tr1.price-ps1.cost)*tr1.quantity)/1000 from stores s, transactions tr1,product_stores ps1 where tr1.product=ps1.pid and tr1.store=ps1.sid and ps1.sid=s.storeid 
                                        AND EXTRACT(DAY FROM '2012-10-30')-EXTRACT(DAY FROM tr1.date)<=10 group by s.region,DAY(tr1.date)";
                                    $result1=mysql_query($statsql1);
                                    $regioname="";
                                    $drawingstate="unstarted";
                                    $chart;
                                    $dataSet;
                                    while ($res1=mysql_fetch_row($result1)){
                                        if($res1[0]!=$regioname){
                                            if($drawingstate=="unstarted"){
                                                $regioname=$res1[0];
                                                $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                                $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                                $drawingstate="started";
                                            }else{
                                                $drawingstate="finished";
                                            }
                                        }
                                        if($drawingstate=="finished"){
                                            $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                            $chart->setTitle("Profit Report for Recent Days for ".$regioname."(Thousand Dollars)");
                                            $chart->render("../images/HaoChart/Top_Day_Region_".$regioname.".png");//这里需要一个路径和文件名称
                                            echo '<img src="../images/HaoChart/Top_Day_Region_'.$regioname.'.png">';
                                            $regioname=$res1[0];
                                            $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                            $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                            $drawingstate="started";
                                        }
                                        $dataSet->addPoint(new Point($res1[1],intval($res1[2])));
                                        
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Profit Report for Recent Days for ".$regioname."(Thousand Dollars)");
                                    $chart->render("../images/HaoChart/Top_Day_Region_".$regioname.".png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Day_Region_'.$regioname.'.png">';
                                    break;
                                case "Yearly Region Performance":
                                    $statsql1 = "select s.region,YEAR(tr1.date),sum((tr1.price-ps1.cost)*tr1.quantity)/1000 from stores s, transactions tr1,product_stores ps1 where tr1.product=ps1.pid and tr1.store=ps1.sid and ps1.sid=s.storeid 
                                        AND EXTRACT(YEAR FROM '2012-10-30')-EXTRACT(YEAR FROM tr1.date)<=10 group by s.region,YEAR(tr1.date)";
                                    $result1=mysql_query($statsql1);
                                    $regioname="";
                                    $drawingstate="unstarted";
                                    $chart;
                                    $dataSet;
                                    while ($res1=mysql_fetch_row($result1)){
                                        if($res1[0]!=$regioname){
                                            if($drawingstate=="unstarted"){
                                                $regioname=$res1[0];
                                                $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                                $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                                $drawingstate="started";
                                            }else{
                                                $drawingstate="finished";
                                            }
                                        }
                                        if($drawingstate=="finished"){
                                            $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                            $chart->setTitle("Profit Report for Recent Years for ".$regioname."(Thousand Dollars)");
                                            $chart->render("../images/HaoChart/Top_Year_Region_".$regioname.".png");//这里需要一个路径和文件名称
                                            echo '<img src="../images/HaoChart/Top_Year_Region_'.$regioname.'.png">';
                                            $regioname=$res1[0];
                                            $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                            $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                            $drawingstate="started";
                                        }
                                        $dataSet->addPoint(new Point($res1[1],intval($res1[2])));
                                        
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Profit Report for Recent Years for ".$regioname."(Thousand Dollars)");
                                    $chart->render("../images/HaoChart/Top_Year_Region_".$regioname.".png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Year_Region_'.$regioname.'.png">';
                                    break;
                                case "Monthly Products Analyze":
                                    $statsql1 = "select * from (select p.Name ,SUM(tr.quantity*(tr.price - ps.cost)) as total
                                             from products p, product_stores ps, transactions tr where tr.product = ps.PID AND tr.store = ps.SID AND ps.PID = p.PRODUCTID
                                             AND DateDiff ('2012-10-30',tr.date)<=60 AND DateDiff ('2012-10-30',tr.date)>=0 group by ps.PID)temp ORDER BY total DESC LIMIT 0,10";
                                    $result1=mysql_query($statsql1);
                                    $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res1=mysql_fetch_row($result1)){
                                         $dataSet->addPoint(new Point($res1[0],  intval($res1[1])));
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Top 10 Products in the Recent Months");
                                    $chart->render("../images/HaoChart/Top_Month_Products_Rank.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Month_Products_Category.png">';
                                    $statsql2="select product_type from product_types where parent_type is null";
                                    $result2=mysql_query($statsql2);
                                    $chart2 = new PieChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet2 = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res2=mysql_fetch_row($result2)){
                                         $sql="select SUM(tr.quantity*(tr.price - ps.cost)) from (select p1.productid,p1.name
                                            ,p1.picture from (select pt1.product_type from product_types pt1 where pt1.product_type='".$res2[0]."' or pt1.parent_type='".$res2[0]."') types,
                                            products p1 where p1.product_type=types.product_type) p, product_stores ps, transactions tr where tr.product = ps.PID AND tr.store = ps.SID AND ps.PID = p.PRODUCTID
                                            AND DateDiff ('2012-10-30',tr.date)<=60 AND DateDiff ('2012-10-30',tr.date)>=0";
                                         $result3=mysql_query($sql);
                                         $res3=mysql_fetch_row($result3);
                                         $dataSet2->addPoint(new Point($res2[0],  intval($res3[0])));
                                    }
                                    $chart2->setDataSet($dataSet2);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart2->setTitle("Profit Proportion of Product Categories In The Recent Months");
                                    $chart2->render("../images/HaoChart/Top_Month_Products_Category.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Month_Products_Rank.png">';
                                    break;
                                case "Daily Products Analyze";
                                    $statsql1 = "select * from (select p.Name ,SUM(tr.quantity*(tr.price - ps.cost)) as total
                                             from products p, product_stores ps, transactions tr where tr.product = ps.PID AND tr.store = ps.SID AND ps.PID = p.PRODUCTID
                                             AND DateDiff ('2012-10-30',tr.date)<=10 AND DateDiff ('2012-10-30',tr.date)>=0 group by ps.PID)temp ORDER BY total DESC LIMIT 0,10";
                                    $result1=mysql_query($statsql1);
                                    $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res1=mysql_fetch_row($result1)){
                                         $dataSet->addPoint(new Point($res1[0],  intval($res1[1])));
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Top 10 Products in the Recent Days");
                                    $chart->render("../images/HaoChart/Top_Day_Products_Rank.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Day_Products_Category.png">';
                                    $statsql2="select product_type from product_types where parent_type is null";
                                    $result2=mysql_query($statsql2);
                                    $chart2 = new PieChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet2 = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res2=mysql_fetch_row($result2)){
                                         $sql="select SUM(tr.quantity*(tr.price - ps.cost)) from (select p1.productid,p1.name
                                            ,p1.picture from (select pt1.product_type from product_types pt1 where pt1.product_type='".$res2[0]."' or pt1.parent_type='".$res2[0]."') types,
                                            products p1 where p1.product_type=types.product_type) p, product_stores ps, transactions tr where tr.product = ps.PID AND tr.store = ps.SID AND ps.PID = p.PRODUCTID
                                            AND DateDiff ('2012-10-30',tr.date)<=10 AND DateDiff ('2012-10-30',tr.date)>=0";
                                         $result3=mysql_query($sql);
                                         $res3=mysql_fetch_row($result3);
                                         $dataSet2->addPoint(new Point($res2[0],  intval($res3[0])));
                                    }
                                    $chart2->setDataSet($dataSet2);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart2->setTitle("Profit Proportion of Product Categories In The Recent Days");
                                    $chart2->render("../images/HaoChart/Top_Day_Products_Category.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Day_Products_Rank.png">';
                                    break;
                                case "Yearly Products Analyze":
                                    $statsql1 = "select * from (select p.Name ,SUM(tr.quantity*(tr.price - ps.cost)) as total
                                             from products p, product_stores ps, transactions tr where tr.product = ps.PID AND tr.store = ps.SID AND ps.PID = p.PRODUCTID
                                             AND DateDiff ('2012-10-30',tr.date)<=365 AND DateDiff ('2012-10-30',tr.date)>=0 group by ps.PID)temp ORDER BY total DESC LIMIT 0,10";
                                    $result1=mysql_query($statsql1);
                                    $chart = new VerticalBarChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res1=mysql_fetch_row($result1)){
                                         $dataSet->addPoint(new Point($res1[0],  intval($res1[1])));
                                    }
                                    $chart->setDataSet($dataSet);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart->setTitle("Top 10 Products in the Recent Year");
                                    $chart->render("../images/HaoChart/Top_Year_Products_Rank.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Year_Products_Category.png">';
                                    $statsql2="select product_type from product_types where parent_type is null";
                                    $result2=mysql_query($statsql2);
                                    $chart2 = new PieChart(650,300);//参数表示需要创建的图像的宽和高
                                    $dataSet2 = new XYDataSet();//实例化一个XY轴数据对象//为这个对象增加四组数据集合，Point对象的第一个参数表示X轴坐标，第二个表示Y轴坐标 
                                    while ($res2=mysql_fetch_row($result2)){
                                         $sql="select SUM(tr.quantity*(tr.price - ps.cost)) from (select p1.productid,p1.name
                                            ,p1.picture from (select pt1.product_type from product_types pt1 where pt1.product_type='".$res2[0]."' or pt1.parent_type='".$res2[0]."') types,
                                            products p1 where p1.product_type=types.product_type) p, product_stores ps, transactions tr where tr.product = ps.PID AND tr.store = ps.SID AND ps.PID = p.PRODUCTID
                                            AND DateDiff ('2012-10-30',tr.date)<=365 AND DateDiff ('2012-10-30',tr.date)>=0";
                                         $result3=mysql_query($sql);
                                         $res3=mysql_fetch_row($result3);
                                         $dataSet2->addPoint(new Point($res2[0],  intval($res3[0])));
                                    }
                                    $chart2->setDataSet($dataSet2);//设置图形的标题，并把它作为一个png文件渲染
                                    $chart2->setTitle("Profit Proportion of Product Categories In The Recent Year");
                                    $chart2->render("../images/HaoChart/Top_Year_Products_Category.png");//这里需要一个路径和文件名称
                                    echo '<img src="../images/HaoChart/Top_Year_Products_Rank.png">';
                                    break;
                            }
                            
                            ?>
                        </div>
                      
            </div>
        </div>
    </body>
</html>
